<script>
function ruyuan(name) {
	$.post('${ctx}/main/ruyuan', {
		"name" : name
	}, function(data) {
		if (data.data == null) {
			$("#zhuyuan").modal('close');
			alert("该科室病房已满，无法入院！");
		} else {
			$("#confirmtitle").html("提示");
			$("#confirmbody").html("是否有病历号");
			$("#confirmdel").html("没有病历号");
			$("#confirmsure").html("有病历号")
			$('#my-confirm').modal({
		        relatedTarget: this,
		        onConfirm: function(options) {
		        	$("#ruyuanname").modal('open');
		        	$("#zhuyuan").modal('close');
		        },
		        onCancel: function() {
		        	$("#ruyuannameinput").modal('open');
		        	$("#zhuyuan").modal('close');
		        }
		      });
			$("#zhuyuan").modal('close');
			
		}
	}, 'json');
}

function blhsearch(){
	var blh = $("#blhinfosearch").val();
	$.post('${ctx}/main/getinfobyblh',{"blh":blh},function(data){
		$("#p_info_name").html(data.patient.P_NAME);
		$("#p_info_sex").html(data.patient.SEX);
		$("#paitentinfo1").show();
	});
	
}

function blhsearchsure(){
    var obj = new Object();
    obj.id = $("#blhinfosearch").val();
	obj.name = $("#p_info_name").html();
	obj.dia = $("#dia2").val();
	obj.sex = $("#p_info_sex").html();
	obj.doc = $("#doc2").val();
	obj.wr = $("#wr2").val();
	obj.bd =$("#bed2").val();
	if(obj.name==""||obj.dia==""||obj.sex==""||obj.doc==""||obj.wr==""||obj.bd==""){
		alert("病人信息不得为空！");
	}
	else{
	$.post('${ctx}/main/updatePatient',{"info":JSON.stringify(obj)},function(data){
		    if(data.success.success){
			$("#myalertbody").html("住院成功！");
			$("#ruyuannameinput").modal('close');
			$("#my-alert").modal('open');
		}
		else
			alert(data.success.fail); 
	});
	
	}
}

function blhsure(){
    var obj = new Object();
	obj.name = $("#name1").val();
	obj.dia = $("#dia1").val();
	obj.sex = $("input[name='sex1']:checked").val();
	obj.doc = $("#doc1").val();
	obj.wr = $("#wr1").val();
	obj.bd =$("#bed1").val();
	if(obj.name==""||obj.dia==""||obj.sex==""||obj.doc==""||obj.wr==""||obj.bd==""){
		alert("病人信息不得为空！");
	}
	else{
	$.post('${ctx}/main/newpaient',{"info":JSON.stringify(obj)},function(data){
		    if(data.success.success){
			$("#myalertbody").html("病历号："+data.success.mid);
			$("#ruyuannameinput").modal('close');
			$("#my-alert").modal('open');
		}
		else
			alert(data.success.fail); 
	});
	
	}
}
</script>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="ruyuanname">
		<div class="am-modal-dialog" style="border-radius: 10px;">
			<div class="am-modal-hd">
				<h2></h2>
				<a href="javascript: void(0)" class="am-close am-close-spin"
					data-am-modal-close>&times;</a>
			</div>
			<div class="am-modal-bd">
				<div>
				<input type="text" id="blhinfosearch" /> <button onclick="blhsearch()">查询</button>
				</div>
				<div id="paitentinfo1" style="display:none">
				   <table class="am-table am-table-bordered am-table-radius am-table-striped">
					<thead>
						<tr>
							<th style="text-align: center">姓名</th>
							<th style="text-align: center">性别</th>
						</tr>
					</thead>
					<tbody id="p_info">
					<tr>
					     <td id="p_info_name"></td>
					     <td id="p_info_sex"></td>
					</tr>
					</tbody>
				</table>
				</div>
				<div id="paitentinfo2" style="display:">
				<table class="am-table am-table-bordered am-table-radius am-table-striped">
				<tr>
				<td>医生ID</td><td>病状</td>
				</tr>
				<tr>
				<td><input id="doc2" /></td><td><input id="dia2" /></td>
				</tr>
				<tr>
				<td>病房号</td><td>病床号</td>
				</tr>
				<tr>
				<td><input id="wr2"/></td><td><input id="bed2" /></td>
				</tr>
				</table>
				<button onclick="blhsearchsure()" >提交</button>
				</div>
			</div>
		</div>
	</div>

	<div class="am-modal am-modal-no-btn" tabindex="-1" id="ruyuannameinput">
		<div class="am-modal-dialog" style="border-radius: 10px;width:1000px">
			<div class="am-modal-hd">
				<h2 id="blh"></h2>
				<a href="javascript: void(0)" class="am-close am-close-spin"
					data-am-modal-close>&times;</a>
			</div>
			<div class="am-modal-bd">
				<div id="paitentinfo" style="display:">
				<table class="am-table am-table-bordered am-table-radius am-table-striped">
				<tr>
				<td colspan="2">姓名</td><td colspan="2">病状</td>
				</tr>
				<tr>
				<td colspan="2"><input id="name1" /></td><td colspan="2"><input id="dia1" /></td>
				</tr>
				<tr>
				<td>性别</td><td>医生ID</td><td>病房号</td><td>病床号</td>
				</tr>
				<tr>
				<td>
				 <input type="radio" name="sex1" value="男" checked>男        &nbsp;
				  <input type="radio" name="sex1" value="女">女
				</td><td><input id="doc1" /></td><td><input id="wr1"/></td><td><input id="bed1" /></td>
				</tr>
				</table>
				<button onclick="blhsure()" >提交</button>
				</div>
			</div>
		</div>
	</div>